from django.db import models
import datetime


# Create your models here.
class Users(models.Model):
    account = models.CharField(default='', max_length=16, unique=True, verbose_name="登录账号")
    username = models.CharField(max_length=16, null=True, db_index=True, verbose_name="用户昵称")
    password = models.CharField(max_length=32, verbose_name="密码")
    gender = models.IntegerField(default=0, verbose_name='性别')  # 性别，0：男，1：女
    birthday = models.DateField(null=True, verbose_name='生日')  # 生日
    money = models.DecimalField(max_digits=10, decimal_places=2, default=0, verbose_name='余额')  # 余额，总位数10，小数位2，默认0
    email = models.EmailField(null=True, verbose_name='邮箱')  # 邮箱
    image = models.ImageField(null=True, verbose_name='头像')  # 头像
    createDatetime = models.DateTimeField(auto_now_add=datetime.datetime.now(), verbose_name='创建时间')  # 创建时间
    updateDatetime = models.DateTimeField(auto_now=datetime.datetime.now(), verbose_name='最近一次修改时间')  # 最近一次修改时间
    isdelete = models.BooleanField(default=False, verbose_name='逻辑删除')  # 逻辑删除

    def __unicode__(self):
        return self.username

    class Meta:
        db_table = "app_users"  # 指定表名


# 创建user表数据
def build_user(num=100):
    for i in range(num):
        Users.objects.create(
            account='%05d' % i,
            username='name%s' % i,
            password=str(i),
            gender=i % 2,
            birthday=datetime.datetime.now() + datetime.timedelta(days=i),
            money=i ** 2 + 12.34 * i + 100,
            email='%05d@qq.com' % i,
            createDatetime=datetime.datetime.now(),
            updateDatetime=datetime.datetime.now(),
            isdelete=i % 2,
        )
